package model

import (
	"gorm.io/gorm"
)

// Account 账户信息
type Account struct {
	Address    string `gorm:"primarykey;type:varchar(90);comment:'以太坊账户地址'"`
	Mail       string `gorm:"type:varchar(30);comment:'邮箱地址'"`
	Username   string `gorm:"type:varchar(30);comment:'用户名'"`
	AlipayID   string `gorm:"type:varchar(30);comment:'支付宝ID'"`
	AlipayName string `gorm:"type:varchar(30);comment:'支付宝用户名'"`

	Nonce uint64 `gorm:"comment:'签名使用的随机值'"` // Nonce 值需要在每次验证签名后进行修改
}

func (a *Account) BeforeCreate(tx *gorm.DB) (err error) {
	a.Nonce++
	return
}

// BeforeUpdate Account 更新前的hook用来更新 Nonce 值
func (a *Account) BeforeUpdate(tx *gorm.DB) (err error) {
	a.Nonce++
	return
}
